package com.liveinstars.gateway.business.service.impl;

import com.liveinstars.gateway.business.entity.AuthSecretDTO;
import com.liveinstars.gateway.business.service.AuthService;
import org.springframework.stereotype.Service;


/**
 * @author: ting
 * @date: 2019-08-02
 */
@Service("webAuthService")
public class WebAuthServiceImpl implements AuthService {

    private static final Long INVALID_SECOND = 300L;

    private static final Long WEB_APP_ID = 1L;

//    @Autowired
//    private AuthSecretManager authSecretManager;

    @Override
    public boolean validateSign(String signStr, Integer version) throws Exception {
        return true;
//        List<AuthSecretDTO> authSecretList = authSecretManager.listTwoNewWebAuthSecret(1L, 2);
//        String msg = null;
//        for (AuthSecretDTO authSecretDTO : authSecretList) {
//            msg = AESPKCS7Util.decrypt(signStr, authSecretDTO.getSecretKeyDTO().getAesKey());
//            if (! StringUtils.isEmpty(msg)) {
//                break;
//            }
//        }
//        if (! StringUtils.isEmpty(msg)) {
//            try {
//                Sign sign = JSON.parseObject(msg, Sign.class);
//                long passTime = (System.currentTimeMillis() / 1000) - sign.getTimestamp();
//                if (sign.getAppId().equals(WEB_APP_ID) && passTime < INVALID_SECOND) {
//                    return true;
//                } else {
//                    return false;
//                }
//            } catch (Exception e){
//                return false;
//            }
//        } else {
//            throw new AuthException("202", "签名失效");
//        }
    }

    @Override
    public AuthSecretDTO getByAppIdAndType(Long appId, Integer version) {
        return null;
//        AuthSecretDTO dto = authSecretManager.getByAppIdVersionAndType(appId, version, 2);
//        return dto;
    }

    @Override
    public AuthSecretDTO getNewAuthSecret(Long appId) {
        return null;
//        AuthSecretDTO newAuthSecret = authSecretManager.getNewAuthSecret(appId, 2);
//        return newAuthSecret;
    }
}
